//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#include "XmlTreeWalker.h"

#include "pugixml.h"

#include "Log.h"

using namespace std;

namespace Green {

  /*!
    Parse XML data file.  Read XML file into a pugi::xml_document, then traverse and handle elementes using passed in pugi::xml_tree_walker class instance to populate XML file properties.
  */
  void parse_xml_file(const string& file_path, const string& file_type, pugi::xml_tree_walker& xml_parser)
  {
    LOG(notice) << "Loading " << file_type << " file: " << file_path << " ..." << endl;

    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file(file_path.c_str());

    if (!result) {
      LOG(fail) << "Faled parsing " << file_type << " file \"" << file_path << "\".  Error description: " << result.description() << endl;
      string fail_str = string("fail-parse-xml-") + file_type + "-file";
      FAIL(fail_str.c_str());
    }

    doc.traverse(xml_parser);
  }

}
